
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><title>Python: module gdata.core</title>
</head><body bgcolor="#f0f0f8">

<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading">
<tr bgcolor="#7799ee">
<td valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial">&nbsp;<br><big><big><strong><a href="gdata.html"><font color="#ffffff">gdata</font></a>.core</strong></big></big></font></td
><td align=right valign=bottom
><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/usr/local/lib/python2.6/dist-packages/gdata/core.py">/usr/local/lib/python2.6/dist-packages/gdata/core.py</a></font></td></tr></table>
    <p><tt>#&nbsp;&nbsp;&nbsp;&nbsp;Copyright&nbsp;(C)&nbsp;2010&nbsp;Google&nbsp;Inc.<br>
#<br>
#&nbsp;&nbsp;&nbsp;Licensed&nbsp;under&nbsp;the&nbsp;Apache&nbsp;License,&nbsp;Version&nbsp;2.0&nbsp;(the&nbsp;"License");<br>
#&nbsp;&nbsp;&nbsp;you&nbsp;may&nbsp;not&nbsp;use&nbsp;this&nbsp;file&nbsp;except&nbsp;in&nbsp;compliance&nbsp;with&nbsp;the&nbsp;License.<br>
#&nbsp;&nbsp;&nbsp;You&nbsp;may&nbsp;obtain&nbsp;a&nbsp;copy&nbsp;of&nbsp;the&nbsp;License&nbsp;at<br>
#<br>
#&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="http://www.apache.org/licenses/LICENSE-2.0">http://www.apache.org/licenses/LICENSE-2.0</a><br>
#<br>
#&nbsp;&nbsp;&nbsp;Unless&nbsp;required&nbsp;by&nbsp;applicable&nbsp;law&nbsp;or&nbsp;agreed&nbsp;to&nbsp;in&nbsp;writing,&nbsp;software<br>
#&nbsp;&nbsp;&nbsp;distributed&nbsp;under&nbsp;the&nbsp;License&nbsp;is&nbsp;distributed&nbsp;on&nbsp;an&nbsp;"AS&nbsp;IS"&nbsp;BASIS,<br>
#&nbsp;&nbsp;&nbsp;WITHOUT&nbsp;WARRANTIES&nbsp;OR&nbsp;CONDITIONS&nbsp;OF&nbsp;ANY&nbsp;KIND,&nbsp;either&nbsp;express&nbsp;or&nbsp;implied.<br>
#&nbsp;&nbsp;&nbsp;See&nbsp;the&nbsp;License&nbsp;for&nbsp;the&nbsp;specific&nbsp;language&nbsp;governing&nbsp;permissions&nbsp;and<br>
#&nbsp;&nbsp;&nbsp;limitations&nbsp;under&nbsp;the&nbsp;License.</tt></p>
<p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#aa55cc">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Modules</strong></big></font></td></tr>
    
<tr><td bgcolor="#aa55cc"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%"><table width="100%" summary="list"><tr><td width="25%" valign=top><a href="simplejson.html">simplejson</a><br>
</td><td width="25%" valign=top></td><td width="25%" valign=top></td><td width="25%" valign=top></td></tr></table></td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ee77aa">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Classes</strong></big></font></td></tr>
    
<tr><td bgcolor="#ee77aa"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%"><dl>
<dt><font face="helvetica, arial"><a href="__builtin__.html#object">__builtin__.object</a>
</font></dt><dd>
<dl>
<dt><font face="helvetica, arial"><a href="gdata.core.html#Jsonc">Jsonc</a>
</font></dt></dl>
</dd>
</dl>
 <p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ffc8d8">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#000000" face="helvetica, arial"><a name="Jsonc">class <strong>Jsonc</strong></a>(<a href="__builtin__.html#object">__builtin__.object</a>)</font></td></tr>
    
<tr bgcolor="#ffc8d8"><td rowspan=2><tt>&nbsp;&nbsp;&nbsp;</tt></td>
<td colspan=2><tt>Represents&nbsp;JSON-C&nbsp;data&nbsp;in&nbsp;an&nbsp;easy&nbsp;to&nbsp;access&nbsp;<a href="__builtin__.html#object">object</a>&nbsp;format.<br>
&nbsp;<br>
To&nbsp;access&nbsp;the&nbsp;members&nbsp;of&nbsp;a&nbsp;JSON&nbsp;structure&nbsp;which&nbsp;looks&nbsp;like&nbsp;this:<br>
{<br>
&nbsp;&nbsp;"data":&nbsp;{<br>
&nbsp;&nbsp;&nbsp;&nbsp;"totalItems":&nbsp;800,<br>
&nbsp;&nbsp;&nbsp;&nbsp;"items":&nbsp;[<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"content":&nbsp;{<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"1":&nbsp;"rtsp://v5.cache3.c.youtube.com/CiILENy.../0/0/0/video.3gp"<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;},<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"viewCount":&nbsp;220101,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"commentCount":&nbsp;22,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"favoriteCount":&nbsp;201<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>
&nbsp;&nbsp;&nbsp;&nbsp;]<br>
&nbsp;&nbsp;},<br>
&nbsp;&nbsp;"apiVersion":&nbsp;"2.0"<br>
}<br>
&nbsp;<br>
You&nbsp;would&nbsp;do&nbsp;the&nbsp;following:<br>
x&nbsp;=&nbsp;gdata.core.<a href="#-parse_json">parse_json</a>(the_above_string)<br>
#&nbsp;Gives&nbsp;you&nbsp;800<br>
x.data.total_items<br>
#&nbsp;Should&nbsp;be&nbsp;22<br>
x.data.items[0].comment_count<br>
#&nbsp;The&nbsp;apiVersion&nbsp;is&nbsp;'2.0'<br>
x.api_version<br>
&nbsp;<br>
To&nbsp;create&nbsp;a&nbsp;<a href="#Jsonc">Jsonc</a>&nbsp;<a href="__builtin__.html#object">object</a>&nbsp;which&nbsp;would&nbsp;produce&nbsp;the&nbsp;above&nbsp;JSON,&nbsp;you&nbsp;would&nbsp;do:<br>
gdata.core.<a href="#Jsonc">Jsonc</a>(<br>
&nbsp;&nbsp;&nbsp;&nbsp;api_version='2.0',<br>
&nbsp;&nbsp;&nbsp;&nbsp;data=gdata.core.<a href="#Jsonc">Jsonc</a>(<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;total_items=800,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;items=[<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;gdata.core.<a href="#Jsonc">Jsonc</a>(<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;view_count=220101,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;comment_count=22,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;favorite_count=201,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;content={<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'1':&nbsp;('rtsp://v5.cache3.c.youtube.com'<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'/CiILENy.../0/0/0/video.3gp')})]))<br>
or<br>
x&nbsp;=&nbsp;gdata.core.<a href="#Jsonc">Jsonc</a>()<br>
x.api_version&nbsp;=&nbsp;'2.0'<br>
x.data&nbsp;=&nbsp;gdata.core.<a href="#Jsonc">Jsonc</a>()<br>
x.data.total_items&nbsp;=&nbsp;800<br>
x.data.items&nbsp;=&nbsp;[]<br>
#&nbsp;etc.<br>
&nbsp;<br>
How&nbsp;it&nbsp;works:<br>
The&nbsp;JSON-C&nbsp;data&nbsp;is&nbsp;stored&nbsp;in&nbsp;an&nbsp;internal&nbsp;dictionary&nbsp;(._dict)&nbsp;and&nbsp;the<br>
getattr,&nbsp;setattr,&nbsp;and&nbsp;delattr&nbsp;methods&nbsp;rewrite&nbsp;the&nbsp;name&nbsp;which&nbsp;you&nbsp;provide<br>
to&nbsp;mirror&nbsp;the&nbsp;expected&nbsp;format&nbsp;in&nbsp;JSON-C.&nbsp;(For&nbsp;more&nbsp;details&nbsp;on&nbsp;name<br>
conversion&nbsp;see&nbsp;_to_jsonc_name.)&nbsp;You&nbsp;may&nbsp;also&nbsp;access&nbsp;members&nbsp;using<br>
getitem,&nbsp;setitem,&nbsp;delitem&nbsp;as&nbsp;you&nbsp;would&nbsp;for&nbsp;a&nbsp;dictionary.&nbsp;For&nbsp;example<br>
x.data.total_items&nbsp;is&nbsp;equivalent&nbsp;to&nbsp;x['data']['totalItems']<br>
(Not&nbsp;all&nbsp;dict&nbsp;methods&nbsp;are&nbsp;supported&nbsp;so&nbsp;if&nbsp;you&nbsp;need&nbsp;something&nbsp;other&nbsp;than<br>
the&nbsp;item&nbsp;operations,&nbsp;then&nbsp;you&nbsp;will&nbsp;want&nbsp;to&nbsp;use&nbsp;the&nbsp;._dict&nbsp;member).<br>
&nbsp;<br>
You&nbsp;may&nbsp;need&nbsp;to&nbsp;use&nbsp;getitem&nbsp;or&nbsp;the&nbsp;_dict&nbsp;member&nbsp;to&nbsp;access&nbsp;certain<br>
properties&nbsp;in&nbsp;cases&nbsp;where&nbsp;the&nbsp;JSON-C&nbsp;syntax&nbsp;does&nbsp;not&nbsp;map&nbsp;neatly&nbsp;to&nbsp;Python<br>
objects.&nbsp;For&nbsp;example&nbsp;the&nbsp;YouTube&nbsp;Video&nbsp;feed&nbsp;has&nbsp;some&nbsp;JSON&nbsp;like&nbsp;this:<br>
"content":&nbsp;{"1":&nbsp;"rtsp://v5.cache3.c.youtube.com..."...}<br>
You&nbsp;cannot&nbsp;do&nbsp;x.content.1&nbsp;in&nbsp;Python,&nbsp;so&nbsp;you&nbsp;would&nbsp;use&nbsp;the&nbsp;getitem&nbsp;as<br>
follows:<br>
x.content['1']<br>
or&nbsp;you&nbsp;could&nbsp;use&nbsp;the&nbsp;_dict&nbsp;member&nbsp;as&nbsp;follows:<br>
x.content._dict['1']<br>
&nbsp;<br>
If&nbsp;you&nbsp;need&nbsp;to&nbsp;create&nbsp;a&nbsp;new&nbsp;<a href="__builtin__.html#object">object</a>&nbsp;with&nbsp;such&nbsp;a&nbsp;mapping&nbsp;you&nbsp;could&nbsp;use.<br>
&nbsp;<br>
x.content&nbsp;=&nbsp;gdata.core.<a href="#Jsonc">Jsonc</a>(_dict={'1':&nbsp;'rtsp://cache3.c.youtube.com...'})<br>&nbsp;</tt></td></tr>
<tr><td>&nbsp;</td>
<td width="100%">Methods defined here:<br>
<dl><dt><a name="Jsonc-__delattr__"><strong>__delattr__</strong></a>(self, name)</dt></dl>

<dl><dt><a name="Jsonc-__delitem__"><strong>__delitem__</strong></a>(self, key)</dt></dl>

<dl><dt><a name="Jsonc-__getattr__"><strong>__getattr__</strong></a>(self, name)</dt></dl>

<dl><dt><a name="Jsonc-__getitem__"><strong>__getitem__</strong></a>(self, key)</dt><dd><tt>#&nbsp;For&nbsp;container&nbsp;methods&nbsp;pass-through&nbsp;to&nbsp;the&nbsp;underlying&nbsp;dict.</tt></dd></dl>

<dl><dt><a name="Jsonc-__init__"><strong>__init__</strong></a>(self, _dict<font color="#909090">=None</font>, **kwargs)</dt></dl>

<dl><dt><a name="Jsonc-__setattr__"><strong>__setattr__</strong></a>(self, name, value)</dt></dl>

<dl><dt><a name="Jsonc-__setitem__"><strong>__setitem__</strong></a>(self, key, value)</dt></dl>

<hr>
Data descriptors defined here:<br>
<dl><dt><strong>__dict__</strong></dt>
<dd><tt>dictionary&nbsp;for&nbsp;instance&nbsp;variables&nbsp;(if&nbsp;defined)</tt></dd>
</dl>
<dl><dt><strong>__weakref__</strong></dt>
<dd><tt>list&nbsp;of&nbsp;weak&nbsp;references&nbsp;to&nbsp;the&nbsp;object&nbsp;(if&nbsp;defined)</tt></dd>
</dl>
</td></tr></table></td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#eeaa77">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Functions</strong></big></font></td></tr>
    
<tr><td bgcolor="#eeaa77"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%"><dl><dt><a name="-jsonc_to_string"><strong>jsonc_to_string</strong></a>(jsonc_obj)</dt><dd><tt>Converts&nbsp;a&nbsp;<a href="#Jsonc">Jsonc</a>&nbsp;<a href="__builtin__.html#object">object</a>&nbsp;into&nbsp;a&nbsp;string&nbsp;of&nbsp;JSON-C.</tt></dd></dl>
 <dl><dt><a name="-parse_json"><strong>parse_json</strong></a>(json_string)</dt><dd><tt>Converts&nbsp;a&nbsp;JSON-C&nbsp;string&nbsp;into&nbsp;a&nbsp;<a href="#Jsonc">Jsonc</a>&nbsp;<a href="__builtin__.html#object">object</a>.<br>
&nbsp;<br>
Args:<br>
&nbsp;&nbsp;json_string:&nbsp;str&nbsp;or&nbsp;unicode&nbsp;The&nbsp;JSON&nbsp;to&nbsp;be&nbsp;parsed.<br>
&nbsp;<br>
Returns:<br>
&nbsp;&nbsp;A&nbsp;new&nbsp;<a href="#Jsonc">Jsonc</a>&nbsp;<a href="__builtin__.html#object">object</a>.</tt></dd></dl>
 <dl><dt><a name="-parse_json_file"><strong>parse_json_file</strong></a>(json_file)</dt></dl>
 <dl><dt><a name="-prettify_jsonc"><strong>prettify_jsonc</strong></a>(jsonc_obj, indentation<font color="#909090">=2</font>)</dt><dd><tt>Converts&nbsp;a&nbsp;<a href="#Jsonc">Jsonc</a>&nbsp;<a href="__builtin__.html#object">object</a>&nbsp;to&nbsp;a&nbsp;pretified&nbsp;(intented)&nbsp;JSON&nbsp;string.</tt></dd></dl>
</td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#55aa55">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Data</strong></big></font></td></tr>
    
<tr><td bgcolor="#55aa55"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%"><strong>__author__</strong> = 'j.s@google.com (Jeff Scudder)'</td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#7799ee">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Author</strong></big></font></td></tr>
    
<tr><td bgcolor="#7799ee"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%">j.s@google.com&nbsp;(Jeff&nbsp;Scudder)</td></tr></table>
</body></html>